﻿using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using WPFExcelReport.Controls;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ChartEx.xaml
    /// </summary>
    public partial class UIMENU : ViewBase
    {
        
        //获取该用户菜单并显示
        public UIMENU()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            ListButtons = new List<TBTN>(); 
        }

        public virtual void OnFUNCTIONChg(DataRow value)
        {

        }

        public virtual void OnUSERIDChg(string value)
        {

        }

        public virtual void OnFUNCChg(string value)
        {

        }

        public virtual void OnFNCGPChg(string value)
        {

        }
        public DocumentBase ActivateReportByDocType(Dictionary<string,object>pm)
        {
            DocumentBase doc = TMV.ActivateReportByDocType((string)pm["DOCTYPE"], (string)pm["DEFAULTUI"], (string)pm["UI"]);
            return doc;
        }

        public DocumentBase ActivateReportByDocType(string doctype, string defaultui = "", string ui = "")
        {
            DocumentBase doc= TMV.ActivateReportByDocType(doctype, defaultui, ui); 
            return doc;
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);

        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                USERID = "";
            }
            else
            {
                USERID = dwMaster["USERID"].ToString();
            }
        }
      
       

        public void ResetSeq(object sender, RoutedEventArgs e)
        {
            VSDDAT.SD22.RESETSEQ("0022", "  ", "MUSEQ", 1);
            ((VICC_MENUDEF)MV).DeleteICC_MENUDEF(null, 0);
            foreach (DataRow row in TBMain.Rows)
            {
             
                row["ROWNID"] = VSDDAT.SD22.GETNEXT("0022", "  ", "MUSEQ", 1);
                ((VICC_MENUDEF)MV).InsertICC_MENUDEF(row, app.company);
            }
        }
        public override void OnSave()
        {
            if (!IsSaved)
                return;
            foreach(DataRow row in TBMain.Rows)
            {
                if (row.RowState == DataRowState.Unchanged) continue;
                TMV.UpdateICC_MENUDEF(row, app.company);
            }
            base.OnSave();
        }
    }
    public partial class UIMENU : ViewBase
    {
        public VICC_MENUDEF TMV
        {
            get
            { 
                return (VICC_MENUDEF)MV;
            }
        }
        public List<TBTN> ListButtons;

        #region ==OnIsgpArticleChanged===========
        public static readonly DependencyProperty IsgpArticleProperty = DependencyProperty.Register("IsgpArticle",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpArticleChanged));
        public bool IsgpArticle
        {
            get
            {
                return (bool)GetValue(IsgpArticleProperty);
            }
            set
            {
                SetValue(IsgpArticleProperty, value);
            }
        }
        private static void OnIsgpArticleChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpArticle = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpPlanChanged===========
        public static readonly DependencyProperty IsgpPlanProperty = DependencyProperty.Register("IsgpPlan",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpPlanChanged));
        public bool IsgpPlan
        {
            get
            {
                return (bool)GetValue(IsgpPlanProperty);
            }
            set
            {
                SetValue(IsgpPlanProperty, value);
            }
        }
        private static void OnIsgpPlanChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpPlan = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpWeavingChanged===========
        public static readonly DependencyProperty IsgpWeavingProperty = DependencyProperty.Register("IsgpWeaving",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpWeavingChanged));
        public bool IsgpWeaving
        {
            get
            {
                return (bool)GetValue(IsgpWeavingProperty);
            }
            set
            {
                SetValue(IsgpWeavingProperty, value);
            }
        }
        private static void OnIsgpWeavingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpWeaving = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpSampleChanged===========
        public static readonly DependencyProperty IsgpSampleProperty = DependencyProperty.Register("IsgpSample",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpSampleChanged));
        public bool IsgpSample
        {
            get
            {
                return (bool)GetValue(IsgpSampleProperty);
            }
            set
            {
                SetValue(IsgpSampleProperty, value);
            }
        }
        private static void OnIsgpSampleChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpSample = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpDyeChanged===========
        public static readonly DependencyProperty IsgpDyeProperty = DependencyProperty.Register("IsgpDye",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpDyeChanged));
        public bool IsgpDye
        {
            get
            {
                return (bool)GetValue(IsgpDyeProperty);
            }
            set
            {
                SetValue(IsgpDyeProperty, value);
            }
        }
        private static void OnIsgpDyeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpDye = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpSizingChanged===========
        public static readonly DependencyProperty IsgpSizingProperty = DependencyProperty.Register("IsgpSizing",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpSizingChanged));
        public bool IsgpSizing
        {
            get
            {
                return (bool)GetValue(IsgpSizingProperty);
            }
            set
            {
                SetValue(IsgpSizingProperty, value);
            }
        }
        private static void OnIsgpSizingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpSizing = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpFinishingChanged===========
        public static readonly DependencyProperty IsgpFinishingProperty = DependencyProperty.Register("IsgpFinishing",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpFinishingChanged));
        public bool IsgpFinishing
        {
            get
            {
                return (bool)GetValue(IsgpFinishingProperty);
            }
            set
            {
                SetValue(IsgpFinishingProperty, value);
            }
        }
        private static void OnIsgpFinishingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpFinishing = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpEKChanged===========
        public static readonly DependencyProperty IsgpEKProperty = DependencyProperty.Register("IsgpEK",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpEKChanged));
        public bool IsgpEK
        {
            get
            {
                return (bool)GetValue(IsgpEKProperty);
            }
            set
            {
                SetValue(IsgpEKProperty, value);
            }
        }
        private static void OnIsgpEKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpEK = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpWarehouseChanged===========
        public static readonly DependencyProperty IsgpWarehouseProperty = DependencyProperty.Register("IsgpWarehouse",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpWarehouseChanged));
        public bool IsgpWarehouse
        {
            get
            {
                return (bool)GetValue(IsgpWarehouseProperty);
            }
            set
            {
                SetValue(IsgpWarehouseProperty, value);
            }
        }
        private static void OnIsgpWarehouseChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpWarehouse = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpWS03Changed===========
        public static readonly DependencyProperty IsgpWS03Property = DependencyProperty.Register("IsgpWS03",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpWS03Changed));
        public bool IsgpWS03
        {
            get
            {
                return (bool)GetValue(IsgpWS03Property);
            }
            set
            {
                SetValue(IsgpWS03Property, value);
            }
        }
        private static void OnIsgpWS03Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpWS03 = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpINOUTINVChanged===========
        public static readonly DependencyProperty IsgpINOUTINVProperty = DependencyProperty.Register("IsgpINOUTINV",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpINOUTINVChanged));
        public bool IsgpINOUTINV
        {
            get
            {
                return (bool)GetValue(IsgpINOUTINVProperty);
            }
            set
            {
                SetValue(IsgpINOUTINVProperty, value);
            }
        }
        private static void OnIsgpINOUTINVChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpINOUTINV = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpSystemChanged===========
        public static readonly DependencyProperty IsgpSystemProperty = DependencyProperty.Register("IsgpSystem",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpSystemChanged));
        public bool IsgpSystem
        {
            get
            {
                return (bool)GetValue(IsgpSystemProperty);
            }
            set
            {
                SetValue(IsgpSystemProperty, value);
            }
        }
        private static void OnIsgpSystemChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpSystem = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpProdChanged===========
        public static readonly DependencyProperty IsgpProdProperty = DependencyProperty.Register("IsgpProd",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpProdChanged));
        public bool IsgpProd
        {
            get
            {
                return (bool)GetValue(IsgpProdProperty);
            }
            set
            {
                SetValue(IsgpProdProperty, value);
            }
        }
        private static void OnIsgpProdChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpProd = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpSalesChanged===========
        public static readonly DependencyProperty IsgpSalesProperty = DependencyProperty.Register("IsgpSales",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpSalesChanged));
        public bool IsgpSales
        {
            get
            {
                return (bool)GetValue(IsgpSalesProperty);
            }
            set
            {
                SetValue(IsgpSalesProperty, value);
            }
        }
        private static void OnIsgpSalesChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpSales = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpFinishChanged===========
        public static readonly DependencyProperty IsgpFinishProperty = DependencyProperty.Register("IsgpFinish",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpFinishChanged));
        public bool IsgpFinish
        {
            get
            {
                return (bool)GetValue(IsgpFinishProperty);
            }
            set
            {
                SetValue(IsgpFinishProperty, value);
            }
        }
        private static void OnIsgpFinishChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpFinish = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgpMaterialChanged===========
        public static readonly DependencyProperty IsgpMaterialProperty = DependencyProperty.Register("IsgpMaterial",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgpMaterialChanged));
        public bool IsgpMaterial
        {
            get
            {
                return (bool)GetValue(IsgpMaterialProperty);
            }
            set
            {
                SetValue(IsgpMaterialProperty, value);
            }
        }
        private static void OnIsgpMaterialChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgpMaterial = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==OnIsgPONeChanged===========
        public static readonly DependencyProperty IsgPONeProperty = DependencyProperty.Register("IsgPONe",
            typeof(bool), typeof(UIMENU),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsgPONeChanged));
        public bool IsgPONe
        {
            get
            {
                return (bool)GetValue(IsgPONeProperty);
            }
            set
            {
                SetValue(IsgPONeProperty, value);
            }
        }
        private static void OnIsgPONeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.IsgPONe = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==USERID===========
        public static readonly DependencyProperty USERIDProperty = DependencyProperty.Register("USERID",
            typeof(string), typeof(UIMENU),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnUSERIDChanged));
        public string USERID
        {
            get
            {
                return (string)GetValue(USERIDProperty);
            }
            set
            {
                SetValue(USERIDProperty, value);
                OnUSERIDChg(value);
            }
        }
        private static void OnUSERIDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.USERID = (string)e.NewValue;
            }
        }
        #endregion


        #region ==ActiveDoc===========
        public static readonly DependencyProperty ActiveDocProperty = DependencyProperty.Register("ActiveDoc",
            typeof(string), typeof(UIMENU),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnActiveDocChanged));
        public string ActiveDoc
        {
            get
            {
                return TMV.ActiveDoc;
            }
            set
            {
                SetValue(ActiveDocProperty, value);
                OnActiveDocChg();
            }
        }
        private static void OnActiveDocChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.ActiveDoc = (string)e.NewValue;
            }
        }
        public virtual void OnActiveDocChg()
        {
            if (TMV == null)
                return;
            TMV.ActiveDoc = ActiveDoc;

        }
        #endregion

        #region ==FUNC===========
        public static readonly DependencyProperty FUNCProperty = DependencyProperty.Register("FUNC",
            typeof(string), typeof(UIMENU),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFUNCChanged));
        public string FUNC
        {
            get
            {
                return (string)GetValue(FUNCProperty);
            }
            set
            {
                SetValue(FUNCProperty, value);
                OnFUNCChg(value);
            }
        }
        private static void OnFUNCChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.FUNC = (string)e.NewValue;
            }
        }
        #endregion

        #region ==FNCGP===========
        public static readonly DependencyProperty FNCGPProperty = DependencyProperty.Register("FNCGP",
            typeof(string), typeof(UIMENU),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFNCGPChanged));
        public string FNCGP
        {
            get
            {
                return (string)GetValue(FNCGPProperty);
            }
            set
            {
                SetValue(FNCGPProperty, value);
                OnFNCGPChg(value);
            }
        }
        private static void OnFNCGPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIMENU;
            if (src != null)
            {
                src.FNCGP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwFN===========
        public static readonly DependencyProperty dwFNProperty = DependencyProperty.Register("dwFN",
            typeof(DataRow), typeof(TUMENU),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwFNChanged));
        public DataRow dwFN
        {
            get
            {
                return (DataRow)GetValue(dwFNProperty);
            }
            set
            {
                SetValue(dwFNProperty, value);
                OnFUNCTIONChg(value);
            }
        }
        private static void OndwFNChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TUMENU;
            DataRow row = (DataRow)e.NewValue;
            if (src != null)
            {
                src.dwFN = row;
            }
        }
        #endregion
    }
}
